{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1ecc443f",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "25/06/19 15:53:49 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable\n",
      "Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties\n",
      "Setting default log level to \"WARN\".\n",
      "To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).\n"
     ]
    }
   ],
   "source": [
    "# 如果不存在，执行以下命令安装：pip install pyspark\n",
    "from pyspark.sql import SparkSession\n",
    "spark = SparkSession\\\n",
    "        .builder\\\n",
    "        .appName(\"jb-20250619\")\\\n",
    "        .getOrCreate()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9efef24e",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                                "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------------+-------------+--------------------+--------+--------------------+-------+-------+-----------------+--------------------+----------+--------------+--------+------+-----------+----------+--------+\n",
      "|        adv_acc_name|  campaign_id|       campaign_name|adset_id|          adset_name|  ad_id|ad_name|campaign_bid_type|       ad_product_id|target_geo|network_status|ad_spend|clicks|conversions|adv_acc_id|      dt|\n",
      "+--------------------+-------------+--------------------+--------+--------------------+-------+-------+-----------------+--------------------+----------+--------------+--------+------+-----------+----------+--------+\n",
      "|RA0000000386_VIZT...|3202503100003|[C]C00000134_VIZT...|   28108|C00000134_VIZTA_D...|1846194|    san|                4|com.td.watcherofr...|        UA|            -1|2.000000|     1|          1|     10011|20250318|\n",
      "+--------------------+-------------+--------------------+--------+--------------------+-------+-------+-----------------+--------------------+----------+--------------+--------+------+-----------+----------+--------+\n",
      "only showing top 1 row\n",
      "\n"
     ]
    }
   ],
   "source": [
    "inpath='/Users/dob/Downloads/00000-1-c33ec9bc-22ff-41ac-a17f-d15018f954ee-00001.parquet'\n",
    "df=spark.read.parquet(inpath)\n",
    "df.createOrReplaceTempView('t_test')\n",
    "df.show(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d34fc5d9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "root\n",
      " |-- adv_acc_name: string (nullable = true)\n",
      " |-- campaign_id: long (nullable = true)\n",
      " |-- campaign_name: string (nullable = true)\n",
      " |-- adset_id: long (nullable = true)\n",
      " |-- adset_name: string (nullable = true)\n",
      " |-- ad_id: long (nullable = true)\n",
      " |-- ad_name: string (nullable = true)\n",
      " |-- campaign_bid_type: integer (nullable = true)\n",
      " |-- ad_product_id: string (nullable = true)\n",
      " |-- target_geo: string (nullable = true)\n",
      " |-- network_status: integer (nullable = true)\n",
      " |-- ad_spend: decimal(12,6) (nullable = true)\n",
      " |-- clicks: long (nullable = true)\n",
      " |-- conversions: long (nullable = true)\n",
      " |-- adv_acc_id: long (nullable = true)\n",
      " |-- dt: string (nullable = true)\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "25/06/19 22:31:31 WARN HeartbeatReceiver: Removing executor driver with no recent heartbeats: 1051396 ms exceeds timeout 120000 ms\n",
      "25/06/19 22:31:31 WARN SparkContext: Killing executors is not supported by current scheduler.\n"
     ]
    }
   ],
   "source": [
    "df.printSchema()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7055e31b-5fbd-4aac-a4bf-3ceb73ba1c8e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
